<template>
  <el-dialog :title="title" :visible.sync="isShow" center @close="closeEvent">
    <el-form label-width="80px" :model="form" :rules="rules" ref="form">
      <el-form-item label="企业编号" prop="eid">
        <el-input v-model="form.eid" />
      </el-form-item>
      <el-form-item label="企业名称" prop="name">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="企业简称" prop="short_name">
        <el-input v-model="form.short_name" />
      </el-form-item>
      <el-form-item label="企业简介" prop="intro">
        <el-input v-model="form.intro" />
      </el-form-item>
      <el-form-item label="学科备注" prop="remark">
        <el-input v-model="form.remark" />
      </el-form-item>
    </el-form>

    <template #footer>
      <div>
        <el-button @click="isShow = false">取消</el-button>
        <el-button type="primary" @click="submit">确认</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { enterpriseadd,enterpriseedit } from "@/api/HmmmQylb";
export default {
  data() {
    return {
      mode: "",
      isShow: false,
      form: {
        eid: "", //	是	string	企业编号
        name: "", //	是	string	企业名称
        short_name: "", //	否	string	学科简称
        intro: "", //	否	string	企业简介
        remark: "",
      },
      rules: {
        eid: [{ required: true, message: "必填", trigger: "change" }],
        name: [{ required: true, message: "必填", trigger: "change" }],
        short_name: [{ required: true, message: "必填", trigger: "change" }],
        intro: [{ required: true, message: "必填", trigger: "change" }],
      },
    };
  },
  methods: {
    // 全局表单验证
    submit() {
      this.$refs.form.validate(async (res) => {
        if (res) {
          if (this.mode === "add") {
            await enterpriseadd(this.form);
            this.$message.success("添加学科成功");
          } else if (this.mode === "edit") {
            await enterpriseedit(this.form);
            this.$message.success("编辑学科成功");
          }
        }
        this.isShow = false;
        this.$emit("getData");
      });
    },
    closeEvent() {
      this.$refs.form.resetFields();
      this.form = {
        eid: "", //	是	string	学科编号
        name: "", //	是	string	学科名称
        short_name: "", //	否	string	学科简称
        intro: "", //	否	string	学科简介
        remark: "",
      };
    },
  },
  computed: {
    title() {
      if (this.mode === "add") {
        return "新增企业";
      } else if (this.mode === "edit") {
        return "编辑企业";
      }
      return "";
    },
  },
};
</script>

<style lang="less" scoped>
::v-deep {
  .el-dialog__header {
    background-color: #66b1ff;
  }
  .el-dialog__title {
    color: #fff;
  }
  .el-dialog__headerbtn .el-dialog__close {
    color: #fff;
  }
}
</style>
